// 已定义一个Shape抽象类、常量PI以及main函数。
// 请在Shape的基础上派生出矩形Rectangle和圆形Circle类，
// 二者都有 GetPerim（）函数计算并返回对象的周长。
// 请编写这两个类的代码，使得在main函数中正确输出两个对象的周长。

//提供的代码如下：
#include <iostream>
using namespace std;
const double PI = 3.14;
class Shape
{
public:
    Shape() {}
    ~Shape() {}
    virtual double GetPerim() const = 0;
};
/*******在此编写代码********/
class Circle : public Shape
{
public:
    Circle(double r);
    double GetPerim() const;
protected:
    double _r;
};

Circle::Circle(double r)
    :_r(r)
{}

double Circle::GetPerim() const
{
    return PI * _r * 2;
}

class Rectangle :public Shape
{
public:
    Rectangle(double width, double height);
    double GetPerim() const;
protected:
    double _width;
    double _height;
};


Rectangle::Rectangle(double width, double height)
    :_width(width)
    ,_height(height)
{}

double Rectangle::GetPerim() const
{
    return (_width + _height) * 2;
}
/*******在此编写代码********/
int main()
{
    Shape* sp;
    double r, width, height;
    cin >> r;
    sp = new Circle(r);
    cout << sp->GetPerim() << endl;
    cin >> width >> height;
    sp = new Rectangle(width, height);
    cout << sp->GetPerim() << endl;
    return 0;
}
